home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sgwnd10 / dialog2.vbs < prev    next >
Encoding:
Text File  |  1998-09-14  |  3.7 KB  |  124 lines

  1. '--------------------------------------------------------------------------
  2. ' Dialog2.vbs - Shows how to open and use dialogs from the WSH scripts.
  3. '
  4. ' REMARKS:
  5. ' - dialog resource must be located in the file that can be loaded with
  6. '   Win32 LoadLibrary() function (EXE, DLL, ...) or you can use empty
  7. '   dialog template located in the SGWINDOW.DLL module. In this case
  8. '   pass empty string as a first parameter for the DoModal method and
  9. '   string "DLG_EMPTY" as a dialog template name.
  10. '
  11. ' This file is part of the SG Window.
  12. ' Copyright (C) 1998 Stinga
  13. ' All rights reserved.
  14. '--------------------------------------------------------------------------
  15. option explicit
  16.  
  17. ' Messages
  18. const wm_CLOSE         = &H0010
  19. const wm_INITDIALOG    = &H0110
  20. const wm_COMMAND       = &H0111
  21.  
  22. const ws_CHILD         = &H40000000
  23. const ws_VISIBLE       = &H10000000
  24. const ws_DISABLED      = &H08000000
  25. const ws_CLIPSIBLINGS  = &H04000000
  26. const ws_CLIPCHILDREN  = &H02000000
  27. const ws_BORDER        = &H00800000
  28. const ws_TABSTOP       = &H00010000
  29.  
  30. const WS_EX_CLIENTEDGE = &H00000200
  31.  
  32. const ES_LEFT          = &H0000
  33. const ES_CENTER        = &H0001
  34. const ES_RIGHT         = &H0002
  35. const ES_MULTILINE     = &H0004
  36. const ES_UPPERCASE     = &H0008
  37. const ES_LOWERCASE     = &H0010
  38. const ES_PASSWORD      = &H0020
  39. const ES_AUTOVSCROLL   = &H0040
  40. const ES_AUTOHSCROLL   = &H0080
  41. const ES_NOHIDESEL     = &H0100
  42. const ES_OEMCONVERT    = &H0400
  43. const ES_READONLY      = &H0800
  44. const ES_WANTRETURN    = &H1000
  45.  
  46. const nCaptionHeight = 25
  47.  
  48. ' Global declarations
  49. Dim g, dlg, rc, sResult
  50. Dim edit, ok
  51. Set dlg  = WScript.CreateObject("SGWindow.Window", "dlg_")
  52. Set g    = WScript.CreateObject("SGWindow.Globals")
  53. Set edit = WScript.CreateObject("SGWindow.Window")
  54. Set ok   = WScript.CreateObject("SGWindow.Window")
  55.  
  56. ' Show dialog
  57. rc = dlg.DoModal("", "DLG_EMPTY", 100, 100)
  58.  
  59. Wscript.DisconnectObject dlg
  60. Set dlg = Nothing
  61. Set edit = Nothing
  62. Set ok = Nothing
  63. Set g = Nothing
  64.  
  65. MsgBox sResult
  66. WScript.Quit
  67.  
  68. '--------------------------------------------------------------------------
  69. ' Dialog window procedure
  70. '--------------------------------------------------------------------------
  71. Sub dlg_Message(msg, wParam, lParam, result)
  72.    result = 0
  73.  
  74.    select case msg
  75.      case wm_INITDIALOG
  76.         Dim style
  77.         style = WS_CHILD + WS_VISIBLE + WS_BORDER + WS_TABSTOP
  78.         
  79.         ' Create edit box
  80.         edit.Create "EDIT", "", style + ES_AUTOHSCROLL, _
  81.                     WS_EX_CLIENTEDGE, 10, 10, dlg.Width-25, 23, dlg.hWnd, 100
  82.         edit.hFont = dlg.hFont
  83.         edit.Text = "This edit box was created by VBScript"
  84.      
  85.         ' Create OK button
  86.         ok.Create "BUTTON", "OK", style, 0, _
  87.                   10, dlg.Height - nCaptionHeight - 40, 80, 30, dlg.hWnd, 1
  88.         ok.hFont = dlg.hFont
  89.         
  90.      case wm_CLOSE
  91.         sResult = "Closed"
  92.         dlg.EndDialog 0
  93.  
  94.      case wm_COMMAND
  95.         Dim bHandled
  96.         bHandled = OnCommand(g.HighWord(wParam), g.LowWord(wParam), lParam)
  97.         if Not bHandled Then 
  98.            result = dlg.CallWindowProc(msg, wParam, lParam)
  99.         end if
  100.      
  101.      case else
  102.         result = dlg.CallWindowProc(msg, wParam, lParam)
  103.    end select
  104. End Sub
  105.  
  106. '--------------------------------------------------------------------------
  107. ' Handle dialog WM_COMMAND messages
  108. '--------------------------------------------------------------------------
  109. Private Function OnCommand(notifyCode, id, hwnd)
  110.    OnCommand = false
  111.    select case id
  112.       case 1 ' OK
  113.           dlg.EndDialog 1
  114.          OnCommand = true
  115.           
  116.       case 2 ' CANCEL
  117.           'dlg.EndDialog 2
  118.            'OnCommand = True
  119.           
  120.       case 100 ' EditBox
  121.    end select
  122. End Function
  123.  
  124.